package com.kobe.game_60;

import com.kobe.util.Prime;

/**
 * It was proposed by Christian Goldbach that every odd composite number can be
 * written as the sum of a prime and twice a square.
 * 
 * 9 = 7 + 212 15 = 7 + 222 21 = 3 + 232 25 = 7 + 232 27 = 19 + 222 33 = 31 +
 * 212
 * 
 * It turns out that the conjecture was false.
 * 
 * What is the smallest odd composite that cannot be written as the sum of a
 * prime and twice a square?
 * 
 * 
 */
public class _46 {

    public static void main(String[] args) {

        int value = 9;
        while (true) {
            if (!Prime.isPrime(value)) {
                if (!isNotSumOfPirme(value)) {
                    System.out.println("The NO. is " + value);
                    break;
                }
            }
            value += 2;
        }
    }

    private static boolean isNotSumOfPirme(int value) {
        int n = 1;
        while (true) {
            int left = value - n * n * 2;
            if (left > 0 && Prime.isPrime(left)) {
                return true;
            } else if (left <= 0) {
                return false;
            }
            n ++;
        }
    }

}
